package org.rcloud.io.service.impl;

import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.TravelapplyMapper;
import org.rcloud.io.model.Scenery;
import org.rcloud.io.model.Travelapply;
import org.rcloud.io.service.TravelapplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2019/3/21.
 */
@Service(value = "TravelapplyService")
public class TravelapplyServiceImpl implements TravelapplyService {
    @Autowired
    TravelapplyMapper travelapplyMapper;

    @Override
    public ResultVo deleteByPrimaryKey(String id) {

        try {
            travelapplyMapper.deleteByPrimaryKey(id);
            return ResultVo.setOK(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo insert(Travelapply record) {

        if (record.equals("") || record == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                travelapplyMapper.insert(record);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public ResultVo insertSelective(Travelapply record) {

        if (record.equals("") || record == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                travelapplyMapper.insertSelective(record);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public PageVo<Travelapply> selectByPrimaryKey(Travelapply record) {
        try {
            List<Travelapply> list = travelapplyMapper.selectByPrimaryKey(record);
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }


    @Override
    public ResultVo updateByPrimaryKeySelective(Travelapply record) {

        if (record.equals("") || record == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                travelapplyMapper.updateByPrimaryKeySelective(record);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public ResultVo updateByPrimaryKey(Travelapply record) {

        if (record.equals("") || record == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                travelapplyMapper.updateByPrimaryKey(record);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public ResultVo selecttimes(Travelapply record) {

        try {
            Travelapply selecttimes = travelapplyMapper.selecttimes(record);
            return ResultVo.setOK(selecttimes);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public PageVo<Travelapply> selectAll() {
        try {
            List<Travelapply> list = travelapplyMapper.selectAll();
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

    @Override
    public PageVo<Travelapply> selectById(Travelapply record) {
        try {
            List<Travelapply> list = travelapplyMapper.selectById(record);
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo selectNum() {

        Travelapply travelapply = new Travelapply();

        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();

        //查询所有报名数
        List<Travelapply> list = travelapplyMapper.selectAll();
        objectObjectHashMap.put("all", list.size());

        //查询春季踏青赏花一日游A线报名数
        travelapply.setName("春季踏青赏花一日游A线");
        List<Travelapply> list1 = travelapplyMapper.selectByPrimaryKey(travelapply);
        objectObjectHashMap.put("A1", list1.size());

        //查询春季踏青赏花一日游A线报名数
        travelapply.setName("春季踏青赏花一日游B线");
        List<Travelapply> list2 = travelapplyMapper.selectByPrimaryKey(travelapply);
        objectObjectHashMap.put("B1", list2.size());

        //查询春季踏青赏花一日游A线报名数
        travelapply.setName("春季踏青赏花二日游A线");
        List<Travelapply> list3 = travelapplyMapper.selectByPrimaryKey(travelapply);
        objectObjectHashMap.put("A2", list3.size());

        //查询春季踏青赏花一日游A线报名数
        travelapply.setName("春季踏青赏花二日游B线");
        List<Travelapply> list4 = travelapplyMapper.selectByPrimaryKey(travelapply);
        objectObjectHashMap.put("B2", list4.size());

        return ResultVo.setOK(objectObjectHashMap);
    }
}
